/**
 * @author LKQ
 * @date 2022/1/4 10:58
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {3, 4, 5, 1, 6, 7};
        solution.numsGame(nums);
    }

    public int[] numsGame(int[] nums) {
        int P = 1_000_000_007;
        int n = nums.length, left = 0, right = 1;
        int[] ans = new int[n];
        int count = 0;
        for (int i = 1; i < n; i++) {
            if (nums[i] - nums[i-1] == 1) {
                count++;
            }
        }
        if (count == n- 1) {
            // 如果前后差值都为1，则返回
            return ans;
        }
        int temp = 0;
        while (right < n) {
            if (nums[right] - nums[left] == 1) {
                ans[right] = 0;
                left++;
            }else {
                temp = nums[left];
                ans[right] = (nums[right] - ans[left] + 1) % P;
            }
            right++;
        }
        return ans;
    }
}
